﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CMTVision.Widgets._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div> 
        <iframe height="10px" src="ShowWidgets.aspx"></iframe>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </div>

    <script type="text/javascript">
        var CTX = {
            initialize: function () {
                jQuery(CTX.Util.is.types).each(function (index, c) {
                    CTX.Util.is[c] = (function (type) {
                        return function (obj) {
                            return Object.prototype.toString.call(obj) == "[object " + type + "]";
                        };
                    })(c);
                });              
            }
        };

        CTX.Util = {
            is: { types: ["Array", "RegExp", "Date", "Number", "String", "Object", "HTMLDocument"] },
            isInMSAjaxMode: function () {
                return typeof (Sys) != "undefined" && typeof (Sys.WebForms) != "undefined";
            },
            addPageLoaded: function (pageLoadedEvent) {
                if (this.isInMSAjaxMode()) {
                    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (sender, e) {
                        pageLoadedEvent(e, sender);
                    });
                }
                else {
                    $(document).ready(function (e) {
                        pageLoadedEvent(e);
                    });
                }
            }
        };

        CTX.Widgets = {
            pageId: null,
            initialize: function (_pageid) {
                this.pageId = _pageid;
            },
            initDragDrop: function (columnClass, widgetClass, newWidgetClass, handleClass, lockWidgetClass, placeholderClass, columnPostBackTrigger) {

                var allColumns = jQuery("." + columnClass);
                //Destroy the old sortable data
                allColumns.each(function () {
                    var plugin = jQuery(this).data("sortable");
                    if (plugin) {
                        plugin.destroy();
                    }
                });

                var itemsSelector = (lockWidgetClass == null)
                                    ? ("." + widgetClass)
                                    : ("." + widgetClass + ":not(." + lockWidgetClass + ")");
                // Init the column's sortable
                allColumns.sortable({
                    connectWith: "." + columnClass,
                    cursor: "move",
                    handle: "." + handleClass,
                    placeholder: placeholderClass,
                    items: itemsSelector,
                    tolerance: "pointer",
                    start: function (event, ui) {
                        ui.placeholder.height(ui.item.height());
                    },
                    change: function (event, ui) {
                        
                    },
                    stop: function (event, ui) {
                    }
                });

                //Init drag new widget to column
                $("." + newWidgetClass).draggable({
                    connectToSortable: "." + columnClass,
                    helper: "clone",
                    tolerance: "pointer"
                });
            }
        };
        CTX.Widgets.WidgetInfo = function (_id, _columnid, _pageid, _index) {
            this.ID = _id;
            this.ColumnID = _columnid;
            this.PageID = _pageid;
            this.Index = _index;
        }
        CTX.Widgets.WidgetInfo.getInstance = function (_id, _columnid, _pageid, _index) {
            return new CTX.Widgets.WidgetInfo(_id, _columnid, _pageid, _index);
        };

        CTX.Services = {
            Widgets: {
                addWidget: function (_widgetInfo, callback) {
                },
                removeWidget: function (_widgetInfo, callback) {
                },
                moveWidget: function (_fromWidgetInfo, _toWidgetInfo, callback) {
                }
            }
        };

        CTX.initialize();
        alert(CTX.Util.isInMSAjaxMode())
         
    </script>
    </form>
</body>
</html>
